package com.bsoft.exchange.service;

import java.util.Date;
import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.bsoft.exchange.dao.his.RegisterMapper;
import com.bsoft.exchange.dao.portal.HospitalInformationMapper;
import com.bsoft.exchange.domain.HospitalInformation;
import com.bsoft.exchange.domain.RegisterDomain;
import com.bsoft.exchange.util.DateUtil;

@Service
public class RegisterService {
	
	public static final String FormatStr ="yyyy-MM-dd";
	
	@Autowired
	RegisterMapper registerMapper;
	
	@Autowired
	HospitalInformationMapper hospitalInformationMapper;
	
	public RegisterDomain getRegistrationForm(String hospitalCode,String hisOrderNumber){
		
		Long jgid;
		Long sbxh;
		jgid = Long.parseLong(hospitalCode);
		sbxh = Long.parseLong(hisOrderNumber);
		Double regFee;
		Integer ghlb;
//		RegisterDomain register = registerMapper.getRegisterById(jgid, sbxh);
		
		RegisterDomain register = registerMapper.getRegisterByYyxh(jgid, sbxh);
		
		Date csny;
		Integer patientAge = null;
		
		if(register != null){
			List<HospitalInformation> hospital = hospitalInformationMapper.selectList(String.valueOf(register.getJgid()));
			for (HospitalInformation jgxx:hospital){
				if (String.valueOf(register.getJgid()).equals(jgxx.getOrganizationId())){
					register.setJgmc(jgxx.getOrganizationName());
				}
			}
			ghlb = register.getGhlb();
			regFee = register.getRegFee();
			
			//3 专家
			if(ghlb!= null && ghlb == 3){
				regFee += register.getZjfy();
			}
			register.setRegFee( regFee );
			
			csny = register.getCsny();
			if(csny!=null){
				try {
					patientAge = DateUtil.getAge(csny);
				} catch (Exception e) {
					// TODO Auto-generated catch block
					e.printStackTrace();
					
				}
			}
			register.setPatientAge(patientAge);
		}
		return register;
	}
	
	
	
}
